using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
using System.Diagnostics;

/// <summary>
/// Summary description for Class1
/// </summary>
namespace marbletrack
{
    public class Floor
    {
        internal VertexPositionNormalTexture[] pointList;
        internal int[] lineListIndices = { 0, 1, 3, 1, 2, 3 };
        internal const float radius = 10000f;

        VertexDeclaration vertexDeclaration;

        public Floor()
        {
            pointList = new VertexPositionNormalTexture[8];
            pointList[0].Position = new Vector3(-20000, 0f, -20000);
            pointList[0].TextureCoordinate = new Vector2(0, 0);
            pointList[1].Position = new Vector3(20000, 0f, -20000);
            pointList[1].TextureCoordinate = new Vector2(0, 1);
            pointList[2].Position = new Vector3(20000, 0f, 20000);
            pointList[2].TextureCoordinate = new Vector2(1, 1);
            pointList[3].Position = new Vector3(-20000, 0f, 20000);
            pointList[3].TextureCoordinate = new Vector2(1, 0);

            //Vertex Declaration
            vertexDeclaration = new VertexDeclaration(Game1.Graphics.GraphicsDevice, VertexPositionNormalTexture.VertexElements);
        }

        public void Update()
        {
            Vector3 temp = new Vector3(Game1.campos.X, 0, Game1.campos.Z);
            pointList[0].Position = temp + new Vector3(-20000, -10f, -20000);
            pointList[1].Position = temp + new Vector3(20000, -10f, -20000);
            pointList[2].Position = temp + new Vector3(20000, -10f, 20000);
            pointList[3].Position = temp + new Vector3(-20000, -10f, 20000);
        }

        public void Draw()
        {
            //Game1.basicEffect.Texture = Game1.blue;
            Game1.Graphics.GraphicsDevice.VertexDeclaration = vertexDeclaration;
            
            Game1.basicEffect.View = Game1.view;
            Game1.basicEffect.Projection = Game1.projectionMatrix;
            Game1.basicEffect.Texture = Game1.floorTexture;

            Game1.basicEffect.Begin();

            foreach (EffectPass pass in Game1.basicEffect.CurrentTechnique.Passes)
            {
                //Game1.basicEffect.FogEnabled = false;
                pass.Begin();
                Game1.Graphics.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
                PrimitiveType.TriangleList, pointList, 0, 4, lineListIndices, 0, 2);
                pass.End();
                //Game1.basicEffect.FogEnabled = true;
            }
            Game1.basicEffect.End();
        }
    }
}